#ifndef CHOICEMODEL_H
#define CHOICEMODEL_H

#include <QAbstractListModel>
#include <QQmlComponent>

struct ChoiceModelData
{
    QString         m_name;
    QQmlComponent*  m_cbtn;
};

class ChoiceModel : public QAbstractListModel
{
    Q_OBJECT

public:
    enum ChoiceRoleName {
        CName = Qt::DisplayRole,
        CBtn,
    };

    static ChoiceModel* instance();

    explicit ChoiceModel(QObject *parent = nullptr);
    ~ChoiceModel();

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    virtual QHash<int,QByteArray> roleNames() const override;

    void remove(const int index);
    void insert(const int index, ChoiceModelData data);

    /**
     * @brief   : 添加新的按钮到主页
     * @param   : ChoiceModelData model数据
     * @author  : BinWatson
     * @version : v1.0
     * @date    : 2022-06-24 10:52:31
     */
    void append(ChoiceModelData data);

public slots:
    /**
     * @brief   : 连接PGLoader的pgLoaderLoadComplete信号
     * @author  : BinWatson
     * @version : v1.0
     * @date    : 2022-06-24 10:55:35
     */
    void onPGLoaderLoadComplete();

private:
    QList<ChoiceModelData> m_datas;
};

#endif // CHOICEMODEL_H
